/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webaccess.retailws.Util;

import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.activation.*;

/**
 *
 * @author Owner
 */
public class SendMailUtil {

    public void sendMail(String fromAddr, String toAddr, String msgSubject, String msgText) {

        Properties properties = new Properties();
        properties = System.getProperties();
        String host = "webaccess.co.in";
        properties.put("mail.smtp.host", host);
        properties.put("mail.smtp.port", "25");

        Session mailSession = Session.getDefaultInstance(properties);
        Message simpleMessage = new MimeMessage(mailSession);

        InternetAddress fromAddress = null;
        InternetAddress toAddress = null;
        try {
            fromAddress = new InternetAddress(fromAddr);
            toAddress = new InternetAddress(toAddr);
        } catch (AddressException ex) {
            ex.printStackTrace();
        }
        try {
            simpleMessage.setFrom(fromAddress);
            simpleMessage.setRecipient(RecipientType.TO, toAddress);
            simpleMessage.setSubject(msgSubject);
            simpleMessage.setText(msgText);
            //simpleMessage.setContent("<h1>This is actual message</h1>", "text/html");
            simpleMessage.setSentDate(new Date());

            Transport.send(simpleMessage);
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }
    }
}
